package com.nondo.rdp.finance.repository;


import com.nondo.rdp.core.domain.attach.Attach;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import com.nondo.rdp.core.common.StatusConstant;

import java.util.Optional;

public interface AttachRepository extends JpaRepository<Attach, Long>,
		JpaSpecificationExecutor<Attach> {
	@Query("select a from Attach a where a.id=:id and delFlag = '"
			+ StatusConstant.DEL_FLAG_NORMAL + "'")
	Optional<Attach> findOne(@Param("id") int id);

	@Modifying
	@Query("update Attach set delFlag='" + StatusConstant.DEL_FLAG_DELETE
			+ "' where id = ?1")
	void deleteById(Long id);

	Attach save(Attach Attach);

	@Modifying
	@Query("update Attach set path=?1,remark=?2 where id = ?3")
	void update(String path, String remark, Long id);

}
